package com.tancire.web.controller.app;

import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.file.bean.SaveFileBean;
import com.tancire.file.service.ISysFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 订单管理Controller
 *
 * @author chenchao
 * @date 2023-11-29
 */
@RestController
@RequestMapping("/net/app/file")
public class FilesAppController extends BaseController {

    @Resource
    private ISysFileService sysFileService;

    /**
     * 上传
     *
     * @param file
     * @return
     */
    @PreAuthorize("@ss.hasPermi('net:user:union')")
    @PostMapping("/upload")
    @ResponseBody
    public AjaxResult upload(@RequestParam("file") MultipartFile file) {
        try {
            SaveFileBean saveFileBean = sysFileService.uploadFile(file, "N");
            return AjaxResult.success(saveFileBean);
        } catch (Exception e) {
            return AjaxResult.error("上传文件异常:" + e.getMessage());
        }
    }


}
